﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TXK.西门子
{
    public class XmzHelper
    {
        public SiemensVar GetXmzStoreType(string address)
        {
            //转换成大写
            address = address.ToUpper();
            SiemensVar var = new SiemensVar() {  VarAddress=address};
            switch (address[0])
            {
                case 'I':
                    var.StoreType = StoreType.Input;
                    break;
                case 'Q':
                    var.StoreType = StoreType.Output;
                    break;
                case 'M':
                    var.StoreType = StoreType.Marker;
                    break;
                case 'D':
                    var.StoreType = StoreType.DataBlock;
                    break;
                case 'T':
                    var.StoreType = StoreType.Counter;
                    break;
                case 'C':
                    var.StoreType = StoreType.Timer;
                    break;
                case 'V':
                    var.StoreType = StoreType.DataBlock;
                    break;
            }
            return var;
        }

        /// <summary>
        /// 获取读取PLC地址的开始位置
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        protected int GetBeingAddress(string address)
        {
            //去掉V1025 前面的V
            //address = address.Substring(1);
            //I1.3地址的情况
            if (address.IndexOf('.') < 0)
                return int.Parse(address) * 8;
            else
            {
                string[] temp = address.Split('.');
                return Convert.ToInt32(temp[0]) * 8 + Convert.ToInt32(temp[1]);
            }
        }

    }
}
